// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var shopp=angular.module('starter', ['ionic','contr','starter.services'],function($httpProvider) {
    // Use x-www-form-urlencoded Content-Type
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

    /**
        * The workhorse; converts an object to x-www-form-urlencoded serialization.
        * @param {Object} obj
        * @return {String}
        */
    var param = function(obj) {
        var query = '', name, value, fullSubName, subName, subValue, innerObj, i;

        for(name in obj) {
            value = obj[name];

            if(value instanceof Array) {
                for(i=0; i<value.length; ++i) {
                    subValue = value[i];
                    fullSubName = name + '[' + i + ']';
                    innerObj = {};
                    innerObj[fullSubName] = subValue;
                    query += param(innerObj) + '&';
                }
            }
            else if(value instanceof Object) {
                for(subName in value) {
                    subValue = value[subName];
                    fullSubName = name + '[' + subName + ']';
                    innerObj = {};
                    innerObj[fullSubName] = subValue;
                    query += param(innerObj) + '&';
                }
            }
            else if(value !== undefined && value !== null)
                query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
        }

        return query.length ? query.substr(0, query.length - 1) : query;
    };

    // Override $http service's default transformRequest
    $httpProvider.defaults.transformRequest = [function(data) {
        return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
    }];
});

shopp.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})




shopp.config(['$ionicConfigProvider',function($ionicConfigProvider) {
    $ionicConfigProvider.platform.android.tabs.position('bottom'); // 设置 android 设备
    // $ionicConfigProvider.tabs.position("bottom"); // 设置 全部 设备

      $ionicConfigProvider.views.transition('none');//设置动画无效

      
}])
shopp.run(['$ionicPlatform','shopData','$rootScope','$state','$location',function($ionicPlatform,shopData,$rootScope,$state,$location){//开始初始化
  $ionicPlatform.ready(function() {

$rootScope.$on('$locationChangeSuccess',function(){//返回前页时，刷新前页  
    parent.location.reload();   
});  
   
 

      shopData.pro(1);
        $rootScope.open=function(index){
          shopData.pro(index);
        $state.go("tab.classify",{id:1},{});
        shopData.goods(index); 
     
      }
    });


            }]);

shopp.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){
    $stateProvider
    // 底部公共样式
   .state('tab', {//定义母模板
    url: '/tab',
    abstract: true,
    templateUrl: 'templates/stair/tab.html'
  })


  .state('tab.shop', {//首页
    url: '/shop',
    views: {
      'shop': {
        templateUrl: 'templates/stair/shop.html',
        controller: 'shopCtrl'
      }
    }
  })
   .state('tab.classify', {//分类
    url: '/classify/:id',
    views: {
      'classify': {
        templateUrl: 'templates/stair/classify.html',
        controller: 'classifyCtrl'
      }
    }
  })
  //   .state('tab.classify1', {//分类详情
  //   url: '/classify1',
  //   views: {
  //     'classify': {
  //       templateUrl: 'templates/ify/classify1.html',
  //       controller: 'classify1Ctrl'
  //     }
  //   }
  // })
  
  
    .state('tab.distribution', {//分销中心
    url: '/distribution',
    views: {
      'distribution': {
        templateUrl: 'templates/stair/distribution.html',
        controller: 'distributionCtrl'
      }
    }
  })
     .state('tab.cart', {//购物车
    url: '/cart',
     cache:false,
    views: {
      'cart': {
        templateUrl: 'templates/stair/cart.html',
        controller: 'cartCtrl'
      }
    }
  })
  
     .state('search', {//搜索栏
    url: '/search',
        templateUrl: 'templates/iyf/search.html',
        controller: 'searchCtrl'
      
   
  })
    .state('classify1', {//分类详情
      url: '/classify1',
      cache:false,
        templateUrl: 'templates/iyf/classify1.html',
        controller: 'classify1Ctrl'
      
   
  })
      .state('tab.my', {//个人中心
    url: '/my',
    cache:false,
    views: {
      'my': {
        templateUrl: 'templates/stair/my.html',
        controller: 'myCtrl'
      }
    }
  })
  .state('product',{//商品详情
    url:'/product',
        templateUrl:'templates/iyf/product.html',
        controller:'productCtrl'
  })
.state('indent',{//填写订单
    url:'/indent',
     cache:false,
        templateUrl:'templates/iyf/indent.html',
        controller:'indentCtrl'
  })
.state('platform',{//支付平台
    url:'/platform',
        templateUrl:'templates/iyf/platform.html',
        controller:'platformCtrl'
  })
.state('logistics',{//物流详情
    url:'/logistics',
        templateUrl:'templates/mess/logistics.html',
        controller:'logisticsCtrl'
  })

    .state('seckill',{//秒杀
      url:'/seckill',
    templateUrl:'templates/seckill.html',
    controller:'seckillCtrl'
    })

    // 分销中心

      .state('commission',{//分销佣金
      url:'/commission',//
        templateUrl:'templates/distrbution/commission.html',
        controller:'commissionCtrl'
  })

            .state('details',{//佣金明细
      url:'/details',//
        templateUrl:'templates/distrbution/details.html',
        controller:'detailsCtrl'
  })
      .state('withdrawal',{//提现明细
      url:'/withdrawal',//
        templateUrl:'templates/distrbution/withdrawal.html',
        controller:'withdrawalCtrl'
  })
      
        .state('share',{//推广二维码
      url:'/share',//
        templateUrl:'templates/distrbution/share.html',
        controller:'shareCtrl'
  })
        
          .state('referrals',{//我的下线
      url:'/referrals',//
        templateUrl:'templates/distrbution/referrals.html',
        controller:'referralsCtrl'
  })
    
    .state('voucher',{//充值
      url:'/voucher',//
        templateUrl:'templates/mysecondary/voucher.html',
        controller:'voucherCtrl'
  })




// 我的二级页面

    .state('personal',{//个人资料
      url:'/personal',//
        templateUrl:'templates/mysecondary/personal.html',
        controller:'personalCtrl'
  })

    .state('intercalate',{//设置
      url:'/intercalate',//
        templateUrl:'templates/mysecondary/intercalate.html',
        controller:'intercalateCtrl'
  })

    .state('message',{//消息中心
      url:'/message',//
        templateUrl:'templates/mysecondary/message.html',
        controller:'messageCtrl'
  })

    .state('wholly',{//待付款和我的订单及订单中心
      url:'/wholly',//
        templateUrl:'templates/mysecondary/wholly.html',
        controller:'whollyCtrl'
  })

    .state('coupn',{//优惠卷
      url:'/coupn',//
        templateUrl:'templates/mysecondary/coupn.html',
        controller:'coupnCtrl'
  })

    .state('apply',{//提现申请
      url:'/apply',//
        templateUrl:'templates/mysecondary/apply.html',
        controller:'applyCtrl'
  })

      .state('record',{//提现记录
      url:'/record',//
        templateUrl:'templates/mysecondary/record.html',
        controller:'recordCtrl'
  })

    .state('security',{//账户安全
      url:'/security',//
        templateUrl:'templates/mysecondary/security.html',
        controller:'securityCtrl'
  })

    .state('certification',{//实名认证
      url:'/certification',//
        templateUrl:'templates/mysecondary/certification.html',
        controller:'certificationCtrl'
  })

    .state('recharge',{//充值记录
      url:'/recharge',//
        templateUrl:'templates/mysecondary/recharge.html',
        controller:'rechargeCtrl'
  })

    .state('collect',{//我的收藏
      url:'/collect',//
        templateUrl:'templates/mysecondary/collect.html',
        controller:'collectCtrl'
  })

    .state('browse',{//浏览记录
      url:'/browse',//
        templateUrl:'templates/mysecondary/browse.html',
        controller:'browseCtrl'
  })

  //   .state('address',{//地址管理
  //     url:'/address',//
  //       templateUrl:'templates/mysecondary/address.html',
  //       controller:'addressCtrl'
  // })
    .state('address',{
      url:'/address',
      cache:false,
      templateUrl:'templates/mysecondary/address.html',
      controller:'addressCtrl'
    })

    .state('modify',{//修改手机号
      url:'/modify',//
        templateUrl:'templates/mysecondary/modify.html',
        controller:'modifyCtrl'
  })
















    // 个人中心
    .state('order',{
        url:'/order',//我的订单的待付款
        templateUrl:'templates/order/order.html',
        controller:'orderCtrl'
  })
  
    .state('delivery',{
        url:'/delivery',//我的订单的收货
        templateUrl:'templates/order/delivery.html',
        controller:'deliveryCtrl'
  })
    .state('assess',{
        url:'/assess',//我的订单的评价
        templateUrl:'templates/order/assess.html',
        controller:'assessCtrl'
  })
      .state('immediately',{
        url:'/immediately',//立即评价
        templateUrl:'templates/order/immediately.html',
        controller:'immediatelyCtrl'
  })










      .state('amend',{
        url:'/amend',//修改登录密码
        templateUrl:'templates/security/amend.html',
        controller:'amendCtrl'
  })
      .state('trade',{
        url:'/trade',//换绑手机
        templateUrl:'templates/security/trade.html',
        controller:'tradeCtrl'
  })






// 设置页


      .state('push',{//推送页面
      url:'/push',//
        templateUrl:'templates/intercalate/push.html',
        controller:'pushCtrl'
  })
        .state('about',{//关于未来购
      url:'/about',//
        templateUrl:'templates/intercalate/about.html',
        controller:'aboutCtrl'
  })
        // 关于未来购
      .state('help',{//使用帮助
      url:'/help',//
        templateUrl:'templates/intercalate/help.html',
        controller:'helpCtrl'
  })  
      .state('statement',{//特别声明
      url:'/statement',//
        templateUrl:'templates/intercalate/statement.html',
        controller:'statementCtrl'
  })
  


  // 消息中心

  .state('logis',{//物流信息
      url:'/logis',//
        templateUrl:'templates/mess/logis.html',
        controller:'logisCtrl'
  })
  .state('mess',{//通知中心
      url:'/mess',//
        templateUrl:'templates/mess/mess.html',
        controller:'messCtrl'
  })



  // 个人资料
 
    .state('photoall',{//最近照片
      url:'/photoall',//
        templateUrl:'templates/personal/photoall.html',
        controller:'photoallCtrl'
  })
      .state('nickname',{//最近照片
      url:'/nickname',//
        templateUrl:'templates/personal/nickname.html',
        controller:'nicknameCtrl'
  })
    

    // 地址管理

 
        .state('addNew',{//添加新地址
      url:'/addNew',//
        templateUrl:'templates/address/addNew.html',
        controller:'addNewCtrl'
  })
      .state('area',{//选择地区
      url:'/area',//
        templateUrl:'templates/address/area.html',
        controller:'areaCtrl'
  })
        .state('street',{//选择街道
      url:'/street',//
        templateUrl:'templates/address/street.html',
        controller:'streetCtrl'
  })
      .state('editor',{//选择街道
      url:'/editor',//
        templateUrl:'templates/address/editor.html',
        controller:'editorCtrl'
  })



// 申请提现



    .state('cosecrad',{//选择银行卡
      url:'/cosecrad',//
        templateUrl:'templates/card/cosecrad.html',
        controller:'cosecradCtrl'
  })
    .state('cardholder',{//添加银行卡
      url:'/cardholder',//
        templateUrl:'templates/card/cardholder.html',
        controller:'cardholderCtrl'
  })
  

// 登录注册

    .state('begin',{//登录页面
      url:'/begin',//
      cache:false,
        templateUrl:'templates/login/begin.html',
        controller:'beginCtrl'
  })
       .state('register',{//注册页
      url:'/register',//
        templateUrl:'templates/login/register.html',
        controller:'registerCtrl'
  })
   .state('register1',{//设置密码
      url:'/register1',//
        templateUrl:'templates/login/register1.html',
        controller:'register1Ctrl'
  })
  .state('retreve',{//找回密码
      url:'/retreve',//
        templateUrl:'templates/login/retreve.html',
        controller:'retreveCtrl'
  })
   .state('retreve1',{//找回密码2
      url:'/retreve1',//
        templateUrl:'templates/login/retreve1.html',
        controller:'retreve1Ctrl'
  })





      $urlRouterProvider.otherwise('tab/shop');



}])

